<template>
  <div>
    <!-- 头部 -->
    <LRheader :center="center" :right="right" :skip="skip"></LRheader>
    <!-- 表单 -->
    <div class="main">
      <van-form @submit="onSubmit" label-align="center">
        <van-field
          v-model="phone"
          name="phone"
          label="手机号码"
          placeholder="请输入手机号码"
          :rules="[{ required: true, message: '请填写正确的11位手机号' }]"
        />
        <van-field
          v-model="mail"
          label="邮箱"
          name="mail"
          placeholder="请填写邮箱"
          :rules="[{ required: true, message: '请填写首字母网易' }]"
        />
        <van-field
          v-model="password"
          type="password"
          label="密码"
          name="password"
          placeholder="请填写密码"
          :rules="[{ required: true, message: '密码没要求' }]"
        />
        <div style="margin: 50px 140px">
          <van-button square block type="info" native-type="submit" color="#999"
            >注册</van-button
          >
        </div>
      </van-form>
    </div>
  </div>
</template>

<script>
import LRheader from "../../components/Nav/LRheader";
import my from "../../config/modules/user";
import Vue from "vue";
import { Form, Field, Button, Icon, Toast } from "vant";
Vue.use(Toast);
Vue.use(Form);
Vue.use(Field);
Vue.use(Button);
Vue.use(Icon);
export default {
  data() {
    return {
      // 组件数据
      center: "注册",
      right: "登录",
      skip: function skip() {
        this.$router.push("/login");
      },
      //   数据库数据
      phone: "",
      mail: "",
      password: "",
    };
  },
  methods: {
    //   注册
    onSubmit(values) {
      // console.log("submit", values);
      this.$http.post(my.register, values).then((res) => {
        if (res.err === 0) {
          Toast.success(res.msg);
          setTimeout(() => {
            this.$router.go(-1);
          }, 2000);
        } else {
          Toast.fail(res.msg);
        }
      });
    },
  },
  created() {
    // 进入该组件隐藏底部导航
    this.$store.commit("my/setIsShow", false);
  },
  //   组件注册
  components: {
    LRheader,
  },
};
</script>

<style scoped>
.main {
  margin-top: 60px  !important;
}
.yangshi {
  margin-left: 50%;
  transform: translateX(-50%);
}
</style>